
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Zookeeper是如何处理节点故障的？ - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>Zookeeper是如何处理节点故障的？ - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">Zookeeper是如何检测集群中节点是否存活的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Zookeeper使用心跳机制来检测节点是否存活。每个节点会定期向集群中的其他节点发送心跳信号（Ping）。如果某个节点在预定时间内没有收到该心跳信号，它就会认为这个节点可能发生了故障。</div>
          </div>
          <div class="card-source">来源: 1. 故障检测</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">当Zookeeper的Leader节点发生故障时，会触发什么核心流程？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">当检测到Leader节点失效时，集群中的Follower和Observer节点会进入选举状态。它们会通过投票过程，并基于ZAB协议，选举出一个获得超过半数支持的节点成为新的Leader，以保证集群的强一致性。</div>
          </div>
          <div class="card-source">来源: 2. 选举机制</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">Zookeeper使用哪种核心协议来保证在处理节点故障时数据的一致性？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Zookeeper使用ZAB协议（Zookeeper Atomic Broadcast协议）。该协议确保所有的写操作在集群中被一致地应用，即使在Leader节点发生故障时，也能保证新的Leader能够继续一致地处理请求。</div>
          </div>
          <div class="card-source">来源: 4. 分布式一致性保障</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">在新Leader选举出来后，Zookeeper如何利用数据快照和事务日志进行数据恢复？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">在故障恢复过程中，新Leader节点会首先读取最新的数据快照（Snapshot）以快速加载大部分数据，然后应用快照之后所有未完成的事务日志（Transaction Log），从而高效地将数据恢复到最新状态并确保一致性。</div>
          </div>
          <div class="card-source">来源: 3. 数据恢复</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">什么是Zookeeper的Quorum机制？它如何保障数据的一致性？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Quorum机制是指Zookeeper的写操作需要得到超过半数（Quorum）的节点确认后才算成功。这个机制可以确保即使部分节点发生故障，只要大多数节点存活并确认了写操作，数据就不会丢失，从而保障了整个系统的数据一致性。</div>
          </div>
          <div class="card-source">来源: 4. 分布式一致性保障</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">在数据恢复完成后，新当选的Leader节点会执行什么操作来确保整个集群的数据一致？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">一旦新的Leader节点被选举出来并且完成了自身的数据恢复，它会将最新的数据状态同步到所有的Follower节点，以确保整个集群的数据最终达到一致。</div>
          </div>
          <div class="card-source">来源: 3. 数据恢复</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
